package krow.dev.gunpobus.view.adapter;

import java.util.ArrayList;
import java.util.List;

import krow.dev.gunpobus.model.StationItem;
import krow.dev.gunpobus.util.ItemViewFactory;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class StationListAdapter extends BaseAdapter{

	private LayoutInflater mLayoutInflater;

	private List<StationItem> mStationItemList;
	
	public StationListAdapter(Context context) {
		
		mLayoutInflater = LayoutInflater.from(context);
		
		mStationItemList = new ArrayList<StationItem>();
	}
	
	public void setStationItemList(List<StationItem> stationItemList){
		
		mStationItemList.clear();
		mStationItemList.addAll(stationItemList);
	}
	
	public List<StationItem> getStationItemList(){
		
		return mStationItemList;
	}
	
	public void clear(){
		mStationItemList.clear();
	}
	
	@Override
	public int getCount() {
		
		return mStationItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mStationItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		StationItem stationItem = mStationItemList.get(position);
		
		View view = ItemViewFactory.createStationView(
				mLayoutInflater,
				stationItem.getName(), 
				stationItem.getSerialNumber(),
				stationItem);
		
		return view;
	}
}
